package EveryDay;

import java.util.*;

/**
 * @Author: Darven
 * @CreateTime: 2024-12-12  00:30
 * @Description: TODO
 */
public class P136 {
    public static void main(String[] args) {
        int[] nums={3,2,4};
        P136Demo p136Demo = new P136Demo();
        int[] ints = p136Demo.twoSum(nums, 6);
        for (int i:ints){
            System.out.println(i);
        }
    }
}

class P136Demo{
    public int singleNumber1(int[] nums) {
        HashMap<Integer, Integer> ans = new HashMap<>();
        for(int a:nums){
            ans.merge(a, 1, Integer::sum);
        }
        Set<Integer> integers = ans.keySet();
        for(Integer key:integers){
            if(ans.get(key)==1){
                return key;
            }
        }

        return 0;

    }

    public int[] singleNumber(int[] nums) {
        HashMap<Integer, Integer> ans = new HashMap<>();
        for(int a:nums){
            ans.merge(a, 1, Integer::sum);
        }
        Set<Integer> integers = ans.keySet();
        int[] arr=new int[2];
        int j=0;
        for(Integer key:integers){
            if(ans.get(key)==1){
                arr[j++]=key;
            }
        }
        return arr;
    }

    public int[] twoSum(int[] nums, int target) {


        int[] ans=new int[2];
        Map<Integer,Integer> map=new HashMap<>();

        for(int i=0;i<nums.length;i++){
            if(map.containsKey(target-nums[i])){
                return new int[]{i,map.get(target-nums[i])};
            }
            map.put(nums[i],i);
        }

        return ans;

    }
}
